From e867d6c921cdcfcde00cd363e1cd4e6092d85397 Mon Sep 17 00:00:00 2001 From: robertl Date: Tue, 28 Jun 2005 22:02:22 +0000 Subject: [PATCH] Make DOP brothers floats. Add writing to GPX. Refactor for commonality and consistent handling of unknown values. Course and speed are a problem in GPX. Working with GPSXML guys now. --- defs.h | 10 +++++----- gpx.c | 33 +++++++++++++++++++++------------ magproto.c | 4 ++-- waypt.c | 4 +++- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/defs.h b/defs.h index fb8b2dabc..ef85b0ffc 100644 --- a/defs.h +++ b/defs.h @@ -246,11 +246,11 @@ typedef struct { /* Optional dilution of precision: positional, horizontal, veritcal. * 1 <= dop <= 50 */ - unsigned char hdop; - unsigned char vdop; - unsigned char pdop; - signed short course; /* Optional: degrees true */ - signed int speed; /* Optional: meters per second. */ + float hdop; + float vdop; + float pdop; + float course; /* Optional: degrees true */ + float speed; /* Optional: meters per second. */ geocache_data gc_data; xml_tag *gpx_extras; diff --git a/gpx.c b/gpx.c index 4deb6a2b3..fb9c45be0 100644 --- a/gpx.c +++ b/gpx.c @@ -1140,21 +1140,34 @@ write_gpx_url(const waypoint *waypointp) } /* - * Write optional accuracty information for a given (way|track|route)point + * Write optional information for a given (way|track|route)point * to the output stream. Done in one place since it's common for all three. * Order counts. */ static void -gpx_write_accuracy(const waypoint *waypointp) +gpx_write_common(const waypoint *waypointp, const char *indent) { + write_gpx_url(waypointp); + write_optional_xml_entity(ofd, indent , "sym", waypointp->icon_descr); + if (waypointp->hdop) { - fprintf(ofd, " %d\n", waypointp->hdop); + fprintf(ofd, "%s%f\n", indent, waypointp->hdop); } if (waypointp->vdop) { - fprintf(ofd, " %d\n", waypointp->vdop); + fprintf(ofd, "%s%f\n", indent, waypointp->vdop); } if (waypointp->pdop) { - fprintf(ofd, " %d\n", waypointp->pdop); + fprintf(ofd, "%s%f\n", indent, waypointp->pdop); + } + if (gpx_wversion_num > 10) { + if (waypointp->course >= 0) { + fprintf(ofd, "%s%f\n", + indent, waypointp->pdop); + } + if (waypointp->speed >= 0) { + fprintf(ofd, "%s%f\n", + indent, waypointp->speed); + } } } @@ -1197,8 +1210,7 @@ gpx_waypt_pr(const waypoint *waypointp) write_optional_xml_entity(ofd, " ", "desc", waypointp->description); write_gpx_url(waypointp); - write_optional_xml_entity(ofd, " ", "sym", waypointp->icon_descr); - gpx_write_accuracy(waypointp); + gpx_write_common(waypointp, " "); fprint_xml_chain( waypointp->gpx_extras, waypointp ); fprintf(ofd, "\n"); @@ -1238,9 +1250,7 @@ gpx_track_disp(const waypoint *waypointp) waypointp->shortname); } write_optional_xml_entity(ofd, " ", "desc", waypointp->notes); - write_gpx_url(waypointp); - write_optional_xml_entity(ofd, " ", "sym", waypointp->icon_descr); - gpx_write_accuracy(waypointp); + gpx_write_common(waypointp, " "); fprintf(ofd, "\n"); } @@ -1285,8 +1295,7 @@ gpx_route_disp(const waypoint *waypointp) write_optional_xml_entity(ofd, " ", "name", waypointp->shortname); write_optional_xml_entity(ofd, " ", "cmt", waypointp->description); write_optional_xml_entity(ofd, " ", "desc", waypointp->notes); - write_optional_xml_entity(ofd, " ", "sym", waypointp->icon_descr); - gpx_write_accuracy(waypointp); + gpx_write_common(waypointp, " "); fprintf(ofd, " \n"); } diff --git a/magproto.c b/magproto.c index 4e0898b06..8c91895d1 100644 --- a/magproto.c +++ b/magproto.c @@ -894,7 +894,7 @@ mag_trkparse(char *trkmsg) struct tm tm; waypoint *waypt; - waypt = xcalloc(sizeof *waypt, 1); + waypt = waypt_new(); memset(&tm, 0, sizeof(tm)); @@ -1089,7 +1089,7 @@ mag_wptparse(char *trkmsg) descr[0] = 0; icon_token[0] = 0; - waypt = xcalloc(sizeof *waypt, 1); + waypt = waypt_new(); sscanf(trkmsg,"$PMGNWPL,%lf,%c,%lf,%c,%d,%c,%[^,],%[^,]", &latdeg,&latdir, diff --git a/waypt.c b/waypt.c index 14bbad644..ee8b43355 100644 --- a/waypt.c +++ b/waypt.c @@ -1,7 +1,7 @@ /* Perform various operations on waypoints. - Copyright (C) 2002 Robert Lipe, robertlipe@usa.net + Copyright (C) 2002-2005 Robert Lipe, robertlipe@usa.net This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -129,6 +129,8 @@ waypt_new(void) wpt = (waypoint *) xcalloc(sizeof (*wpt), 1); wpt->altitude = unknown_alt; + wpt->course = -999.0; + wpt->speed = -999.0; return wpt; } -- 2.30.2